/**
 * jims
 */
package com.jims.master.modules.csm.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jims.master.common.data.StringData;
import com.jims.master.common.persistence.Page;
import com.jims.master.common.web.BaseController;
import com.jims.master.common.utils.StringUtils;
import com.jims.master.modules.csm.entity.ExpPriceAdjustRecord;
import com.jims.master.modules.csm.service.ExpPriceAdjustRecordService;

/**
 * 消耗品调价记录表Controller
 * @author CTQ
 * @version 2017-07-08
 */
@Controller
@RequestMapping(value = "${adminPath}/csm/expPriceAdjustRecord")
public class ExpPriceAdjustRecordController extends BaseController {

	@Autowired
	private ExpPriceAdjustRecordService expPriceAdjustRecordService;

	@ModelAttribute
	public ExpPriceAdjustRecord get(@RequestParam(required=false) String id) {
		ExpPriceAdjustRecord entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = expPriceAdjustRecordService.get(id);
		}
		if (entity == null){
			entity = new ExpPriceAdjustRecord();
		}
		return entity;
	}

    /**
     * 耗材调价盈亏统计首页
     * @param expPriceAdjustRecord
     * @param request
     * @param response
     * @param model
     * @return
     */
	@RequiresPermissions("user")
	@RequestMapping(value = {"index", ""})
	public String list(ExpPriceAdjustRecord expPriceAdjustRecord, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<ExpPriceAdjustRecord> page = expPriceAdjustRecordService.findPage(new Page<ExpPriceAdjustRecord>(request, response), expPriceAdjustRecord);
		model.addAttribute("page", page);
		return "modules/csm/expPriceAdjustRecordIndex";
	}

	@RequiresPermissions("user")
	@RequestMapping(value = "form")
	public String form(ExpPriceAdjustRecord expPriceAdjustRecord, Model model) {
		model.addAttribute("expPriceAdjustRecord", expPriceAdjustRecord);
		return "modules/csm/expPriceAdjustRecordForm";
	}

	@RequiresPermissions("user")
	@RequestMapping(value = "save")
	@ResponseBody
	public StringData save(ExpPriceAdjustRecord expPriceAdjustRecord, Model model) {
	    StringData data=new StringData();
		int i=expPriceAdjustRecordService.save(expPriceAdjustRecord);
        if(i>0){
            data.setCode("success");
            data.setData("保存消耗品调价记录表成功");
        }else{
            data.setCode("error");
            data.setData("保存消耗品调价记录表失败");
        }
        return data;
	}
	@RequiresPermissions("user")
	@RequestMapping(value = "delete")
	@ResponseBody
	public StringData delete(ExpPriceAdjustRecord expPriceAdjustRecord) {
	    StringData data=new StringData();
		int i=expPriceAdjustRecordService.delete(expPriceAdjustRecord);
        if(i>0){
            data.setCode("success");
            data.setData("删除消耗品调价记录表成功");
        }else{
            data.setCode("error");
            data.setData("删除消耗品调价记录表失败");
        }
		return data;
	}

}